package com.it.schoolbookshop_back.mapper;

import com.it.schoolbookshop_back.entities.po.Report;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 举报记录Mapper接口
 */
@Mapper
public interface ReportMapper {
    
    /**
     * 根据举报人ID查询举报记录
     * @param reporterId 举报人ID
     * @return 举报记录列表
     */
    @Select("SELECT * FROM reports WHERE reporter_id = #{reporterId} ORDER BY created_at DESC")
    List<Report> selectByReporterId(@Param("reporterId") Integer reporterId);
    
    /**
     * 根据被举报人ID获取举报记录
     * 
     * @param reportedId 被举报人ID
     * @return 举报记录列表
     */
    @Select("SELECT * FROM reports WHERE reported_id = #{reportedId} ORDER BY created_at DESC")
    List<Report> getReportsByReportedId(Integer reportedId);
    
    /**
     * 根据书籍ID获取举报记录
     * 
     * @param bookId 书籍ID
     * @return 举报记录列表
     */
    @Select("SELECT * FROM reports WHERE book_id = #{bookId} ORDER BY created_at DESC")
    List<Report> getReportsByBookId(Integer bookId);
    
    /**
     * 插入举报记录
     * @param report 举报记录
     * @return 影响行数
     */
    @Insert("INSERT INTO reports (reporter_id, reported_id, book_id, reason, details, status) " +
            "VALUES (#{reporterId}, #{reportedId}, #{bookId}, #{reason}, #{details}, 'pending')")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Report report);
    
    /**
     * 更新举报状态
     * 
     * @param reportId 举报ID
     * @param status 状态
     * @param adminComment 管理员备注
     * @return 影响行数
     */
    @Update("UPDATE reports SET status = #{status}, admin_comment = #{adminComment} WHERE id = #{reportId}")
    int updateReportStatus(@Param("reportId") Integer reportId, @Param("status") String status, @Param("adminComment") String adminComment);
    
    /**
     * 获取指定ID的举报记录
     * 
     * @param id 举报ID
     * @return 举报记录
     */
    @Select("SELECT * FROM reports WHERE id = #{id}")
    Report getReportById(Integer id);
    
    /**
     * 获取所有举报记录
     * 
     * @return 所有举报记录列表
     */
    @Select("SELECT * FROM reports ORDER BY created_at DESC")
    List<Report> getAllReports();
} 